<?php if(isset($_GET['print'])){
$this->layout = "plain"; 
Configure::write("debug",0);
?>
<style type="text/css">
body{background-image:none;}
  .invoice, #header{
    width: 70%;
    margin-left: 15%;
    margin-right: 15%;
  }
  #pay_options_div
  {
    display: none;
  }
  .print,#footer,.bizinfo_edit
  {
     display: none;
  }
  .business_info
  {
    margin-right: 20px;
  }
  h1{color:#000;
  padding:0px;
  padding-top:10px;}
</style>
<script>
$(document).ready(function(){
  window.print();
})
</script>
<?php } ?>
<?php 

	$html->css("/paid_listings/css/style.css",array(),null,false);
	$html->css("/paid_listings/css/invoice.css",array(),null,false); 

?>
<?php
   $businessInformation = $session->read("Auth.User.business_information");
   $editProfileUrl = '/users/editProfile/buniessInfo:1?backTo='.urlencode('/'.$this->params['url']['url']);
   echo " ";
   if(!$businessInformation)
   {
     echo $html->link(__("Add your business information"),$editProfileUrl,array("class"=>"bizinfo_edit fl"));
   }else{
     echo $html->link(__("Change your business information"),$editProfileUrl,array("class"=>"bizinfo_edit fl")); 
     }?>

<?php echo $html->link(__("Print"),array($order['Order']['id'],"?"=>array("print"=>1)),array("class"=>"print fr","onclick"=>"window.open($(this).attr('href'),'_print','height=600,width=800,menubar=false');return false;"))?>
<div class="invoice">
	<div class="invoice_head">
		<div class="invoice_company_logo unit size2of3">
			<?php 
              if(cr("PaidListingConfig.company_logo"))
              {
                echo $html->image('/paid_listings/img/'.cr("PaidListingConfig.company_logo"),array("alt"=>cr("cmsConfig.Backend.siteName")));
              }else
              {
                echo "".cr("cmsConfig.Backend.siteName")."";
              }
             ?>
		</div>
		<div class="invoice_business_information unit size1of3">
			<?php 
				echo nl2br(cr("PaidListingConfig.business_information")); 
			?>
		</div>
		<div class="clear"></div>
	</div>
	<div class="invoice_content">
      <div>
		<div class="order_info unit size1of2">
			<span class="order_var"><?php echo __("Order Id") ?></span>
			<span><?php echo $order['Order']['id']?></span>
			<br />
			<span class="order_var"><?php echo __("Date")?></span>
			<span><?php echo $time->format('Y-m-d',$order['Order']['created']);?></span>
			<br />
			<span class="order_var"><?php echo __("Payment Status")?></span>
			<span><?php echo cri('Order')->showValue('status',$order['Order'],'Order')?></span>
		</div>
        <div class="business_info unitExt">
            <?php
               if($businessInformation)
               {
                 echo nl2br($businessInformation);
               }?>
        </div>
      </div>
	  <div class="clear"></div>
		<div class="invoice_table">
			<table>
				<tr>
					<th>
						<?php echo __("Plan Name")?>
					</th>
					<th>
						<?php echo __("Description") ?>
					</th>
					<th>
						<?php echo __("Listing");?>
					</th>
					<!--<th>
						<?php echo __("Start Date")?>
					</th>
					<th>
						<?php echo __("End Date")?>
					</th>-->
					<th>
						<?php echo __("Tax")?>
					</th>
					<th>
						<?php echo __("Price")?>
					</th>
				</tr>
				<tr>
					<td>
						<?php echo $order['ListingPlan']['plan_info']['Plan']['title']?>
					</td>
					<td>
						<?php echo $order['ListingPlan']['plan_info']['Plan']['description']?>
					</td>
					<td>
						<?php 
							if(Listing::PUBLISH == $listing['Listing']['status'])
							{
								echo $html->link($listing['Listing']['title'],$listing['Listing']['viewUrl']);
							}else
							{
								echo $listing['Listing']['title'];
							}
						?>
					</td>
					<td>
						<?php echo $order['Order']['tax']?>
					</td>
					<td>
						<?php echo $order['Order']['currency_symbol'].$order['Order']['price'];?>
					</td>
				</tr>
				<tr class="noborder">
					<td colspan="3"> 
						
					</td>
					<td class="noborder">
						<?php echo __("Sub Total")?>	
					</td>
					<td>
						<?php echo $order['Order']['currency_symbol'].$order['Order']['price'];?>
					</td>
				</tr>
				<tr class="noborder">
					<td colspan="3"> 
						
					</td>
					<td class="noborder">
						<?php echo sprintf(__("Tax @ %s%%"),($order['Order']['tax']))?>
					</td>
					<td>
						<?php echo round(($order['Order']['tax']*$order['Order']['price'])/100,2)?>
					</td>
				</tr>
				<tr class="noborder">
						<td colspan="3"> 
						
						</td>						
						<td class="noborder">
							<?php echo __("Total Amount") ?>
						</td>
						<td>
							<?php echo $order['Order']['currency_symbol'].$order['Order']['total_amount'];?>
						</td>
				</tr>
			</table>
		</div>
	</div>
<div id="pay_options_div" class="pay_options">	
<?php if($order['Order']['status'] == Order::STATUS_PENDING || $order['Order']['status'] == Order::STATUS_INCOMPLETE || $order['Order']['status'] == Order::STATUS_PROCESSING){?>
<strong><?php echo __("Please select a payment gateway")?></strong>
<?php echo $form->create("Order",array("action"=>"process"));
	echo $form->input("id",array("value"=>$order['Order']['id'],'type'=>"hidden"));
 ?>
<div class="plan_info">
<?php 
	foreach(cri("PaidListings.PaymentHandler")->getPaymentHandlers() as $handlerName => $handlerObject)
	{
		if($handlerObject->isEnabled() == false || ($order['Order']['payment_type']) == Plan::PAYMENT_SUBSCRIPTION && $handlerObject->useForSubscription() == false)
		{
			continue;
		}
		$paymentId = $handlerName."_id";
	?>
	<div>
	<input id="<?php echo $paymentId?>" type="radio" name="data[Order][payment_gateway]"  value="<?php echo $handlerName?>"/>
	<label for"<?php echo $paymentId?>">
	<?php
		$img = $handlerObject->getFieldValue("image_name");
        if($img)
		{
          echo $html->image('/paid_listings/img/'.$img,array("alt"=>$handlerObject->getFieldValue("title")));
        }else
        {
          echo "<strong>".$handlerObject->getFieldValue("title").'</strong>';
        }
	?></label>
	</div>		
<?php	}
?>
</div>

<?php if(strlen(cr('PaidListingConfig.term_of_service'))){?>
	<div>
	<div>
			<strong><?php echo __("Terms and conditions")?>:</strong>
	</div>
	<div style=";max-height:150px;min-height: 50px;overflow: auto;background-color: white;border:1px solid #666666 ">
		<?php echo cr('PaidListingConfig.term_of_service');?>
	</div>
	<?php echo $form->input("term",array("label"=>__("I agree to above mentioned Terms and conditions"),'type'=>"checkbox","div"=>array('class'=>"required input checkbox")))?>
	</div>
	<script>
		$(document).ready(function(){
			var submit = $('#OrderProcessForm').find("input[type='submit']");
			submit.click(function (){
				if($("#OrderTerm").attr("checked") == false)
				{
					alert("<?php echo __("Please agree with our terms and conditions to continue.")?>");
					return false;
				}
				return true;
			})
		});
	</script>
<?php } ?>	
<?php echo $form->end(__("Checkout"));?>
<div class="clear"></div>
<?php } ?>
</div>
</div>